<?php

namespace App\Http\Middleware;

use Closure;

class SwitchLanguage
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
    	if(Session('locale') && array_key_exists(Session::get('locale'), config('app.locales'))){
    		App::setLocale(Session::get('locale'));
    	}else{
    		App::setLocale(config('app.locale'));
    	}
    	
        return $next($request);
    }
    
}
